<script type="text/javascript" src="../../js/ajaxfileupload.js"></script>

<div class="modal-body">
	<form id="user-form" name="user-form" class="form-horizontal">
		<input type="hidden" name="id" id="projectId">
		<input type="hidden" name="createTime" data-flag="date" data-format="yyyy-MM-dd HH:mm:ss">
		<input type="hidden" name="deleted">
		<div class="box-body">
			<div class="col-md-12">
				<div class="form-group">
					<label for="type" class="col-sm-2 control-label">监测位置</label>
					<div class="col-sm-6">
						<select id="zht" class="form-control" name="type">
							<!-- <option value="041e55f6-95b1-4650-a6c2-8ccc64263c87">一号坝</option>
							<option value="141e55f6-95b1-4650-a6c2-8ccc64263c85">二号坝</option> -->
						</select>
					</div>
					<div class="clo-sm-4">
						<a id="template" href="javascript:void(0)" onclick="downTemplate()">数据导入模板下载</a>
					</div>
				</div>
				<div class="form-group">
					<label for="description" class="col-sm-2 control-label">上传文件</label>
					<div class="col-sm-10">
						<div id="uploadfileQueue"></div>
						<input type="file" class="form-control" id="file"
							name="file" placeholder="上传文件">
					</div>
				</div>
			</div>
		</div>
		<!-- /.box-body -->
		<div class="box-footer text-right">
			<!--以下两种方式提交验证,根据所需选择-->
			<button type="button" class="btn btn-default" data-btn-type="cancel" onclick="dialog_close()">取消</button>
			<button type="button" class="btn btn-primary" data-btn-type="save" onclick="importData()">导入</button>
		</div>
		<!-- /.box-footer -->
	</form>
</div>
<script type="text/javascript">
	$(document).ready(function(){
		//初始化灾害体下拉列表
		initZhtSelect();
	});
	
	function importData(){
		var zht = $("#zht").val();
		var url = "../../thirddata/import/" + dataType + "/" +zht ;
		$.ajaxFileUpload({  
	        url : url, //用于文件上传的服务器端请求地址  
	        secureuri : false, //一般设置为false  
	        fileElementId : 'file', //文件上传空间的id属性  <input type="file" id="file" name="file" />  
	        type : 'POST',  
	        dataType : 'json', //返回值类型 一般设置为json  
	        success : function( data, status) {//服务器成功响应处理函数  
	             alert(data.msg);  
	        },  
	        error : function( data, status, e){//服务器响应失败处理函数  
	            alert(data.msg);  
	        }  
	    });  
	    return false;  
	}
	
	//查询所有的灾害体，初始化下拉列表
	function initZhtSelect() {
		var url = "../../tbl_zht/list";
		var paramMap = {};
		/* if( area_code && area_code != "" ){
			paramMap.area_code = area_code;
		} */
		paramMap.deleted = 0;
		var json_data = JSON.stringify( paramMap );
		$.ajax({
			  url: url,
			  type : 'post',
			  async : false,
			  data: json_data,
			  contentType: "application/json; charset=utf-8",
			  dataType: "json",
			  success: function( json ) {
				  $(json.data).each(function(){
						$( "#zht" ).append("<option value='"+ this.id +"'>"+ this.name +"</option>");
				  });
			  }
		});
	}
	
	function downTemplate() {
		var url = "";
		
		if( dataType == "tbl_deep_move_device_data" ){
			url = "../../template/template_deep_move.xlsx";
		}else if( dataType == "tbl_rain_device_data" ){
			url = "../../template/template_rain.xlsx";
		}else if( dataType == "tbl_surface_move_device_data" ){
			url = "../../template/template_surface_move.xlsx";
		}else if( dataType == "tbl_water_device_data" ){
			url = "../../template/template_water.xlsx";
		}else if( dataType == "tbl_pressure_device_data" ){
			url = "../../template/template_pressure.xlsx";
		}else if( dataType == "tbl_flow_device_data" ){
			url = "../../template/template_flow.xlsx";
		}
		
		//$("#template").attr("href", url);
		window.open(url);
	}
	
	function dialog_close(){
		global.dialog.close()
	}
</script>